package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.sl.domain.*;
import com.ruoyi.sl.service.ISlSpecialService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.service.ISlOddjobOmemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零工操作人Controller
 * 
 * @author admin
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/sl/omember")
public class SlOddjobOmemberController extends BaseController
{
    @Autowired
    private ISlOddjobOmemberService slOddjobOmemberService;
    @Autowired
    private ISlSpecialService slSpecialService;

    /**
     * 查询未提交报工项的操作人列表
     */
    @PreAuthorize("@ss.hasPermi('sl:rwork:list')")
    @GetMapping("/notmember")
    public AjaxResult notMemberList(SlOddjob slOddjob)
    {
        LoginUser loginUser = getLoginUser();
        slOddjob.setOddjobUser(getLoginUser().getUsername());
        List<SlOddjobOmember> list = slOddjobOmemberService.selectNotSlOddjobOmemberList(slOddjob);
        //报工人是不是特殊系人员，特殊系不参与生产但是要填出勤天数
//        SlSpecial slSpecial = slSpecialService.selectSlSpecialByUserName(getLoginUser().getUsername());
//        if(StringUtils.isNotNull(slSpecial)){
//            //不参与生产,出勤人加上他
//            if(slSpecial.getIsProduce().equals("1")){
//                SlOddjobOmember slOddjobOmember = new SlOddjobOmember();
//                slOddjobOmember.setOmemberUser(slSpecial.getUserName());
//                slOddjobOmember.setOmemberNick(slSpecial.getNickName());
//                list.add(slOddjobOmember);
//            }
//        }

        return success(list);
    }

    /**
     * 查询零工操作人列表
     */
    @PreAuthorize("@ss.hasPermi('sl:oddjob:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlOddjobOmember slOddjobOmember)
    {
        startPage();
        List<SlOddjobOmember> list = slOddjobOmemberService.selectSlOddjobOmemberList(slOddjobOmember);
        return getDataTable(list);
    }

    /**
     * 导出零工操作人列表
     */
    @PreAuthorize("@ss.hasPermi('sl:oddjob:export')")
    @Log(title = "零工操作人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlOddjobOmember slOddjobOmember)
    {
        List<SlOddjobOmember> list = slOddjobOmemberService.selectSlOddjobOmemberList(slOddjobOmember);
        ExcelUtil<SlOddjobOmember> util = new ExcelUtil<SlOddjobOmember>(SlOddjobOmember.class);
        util.exportExcel(response, list, "零工操作人数据");
    }

    /**
     * 获取零工操作人详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:oddjob:query')")
    @GetMapping(value = "/{omemberId}")
    public AjaxResult getInfo(@PathVariable("omemberId") Long omemberId)
    {
        return success(slOddjobOmemberService.selectSlOddjobOmemberByOmemberId(omemberId));
    }

    /**
     * 新增零工操作人
     */
    @PreAuthorize("@ss.hasPermi('sl:oddjob:add')")
    @Log(title = "零工操作人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlOddjobOmember slOddjobOmember)
    {
        return toAjax(slOddjobOmemberService.insertSlOddjobOmember(slOddjobOmember));
    }

    /**
     * 修改零工操作人
     */
    @PreAuthorize("@ss.hasPermi('sl:oddjob:edit')")
    @Log(title = "零工操作人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlOddjobOmember slOddjobOmember)
    {
        return toAjax(slOddjobOmemberService.updateSlOddjobOmember(slOddjobOmember));
    }

    /**
     * 删除零工操作人
     */
    @PreAuthorize("@ss.hasPermi('sl:oddjob:remove')")
    @Log(title = "零工操作人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{omemberIds}")
    public AjaxResult remove(@PathVariable Long[] omemberIds)
    {
        return toAjax(slOddjobOmemberService.deleteSlOddjobOmemberByOmemberIds(omemberIds));
    }
}
